package com.cswnode.Config;

import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;


@Configuration
public class KaptchaConfig {
    @Bean
    public Producer kaptchaProducer(){
       Properties properties = new Properties();
       //宽度
       properties.setProperty("kaptcha.image.width","100");
       //长度
       properties.setProperty("kaptcha.image.height","40");
       //字体大小
       properties.setProperty("kaptcha.textproducer.font.size","32");
       //配置字体颜色
       properties.setProperty("kaptcha.textproducer.font.color","black");
       //配置string字符串
       properties.setProperty("kaptcha.textproducer.char.string","123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
               "abcdefghijklmnopqrstuvwxyz");
       //配置个数
        properties.setProperty("kaptcha.textproducer.char.length","4");
        //渲染干扰
        properties.setProperty("kaptcha.noise.impl","com.google.code.kaptcha.impl.NoNoise");

        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        Config config = new Config(properties);
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }
}
